package com.tebiecloud.order.server.controller.feign;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tebiecloud.common.model.ResultBody;
import com.tebiecloud.common.utils.ResultBodyUtils;
import com.tebiecloud.order.client.model.entity.OrderGoods;
import com.tebiecloud.order.client.model.entity.Orderr;
import com.tebiecloud.order.client.service.IOrderGoodsServiceCient;
import com.tebiecloud.order.client.service.IOrderServiceClient;
import com.tebiecloud.order.server.service.OrderGoodsService;
import com.tebiecloud.order.server.service.OrderrService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/feign/ordergoods")
public class OrdGoodsController implements IOrderGoodsServiceCient {

    @Autowired
    OrderrService orderrService;

    @Autowired
    OrderGoodsService orderGoodsService;

    /**
     * 获取我未核销的权益
     * @param userId
     * @return
     */
    @PostMapping("selectOrderGoods")
    @Override
    public ResultBody<List<OrderGoods>> selectOrderGoods(@RequestParam("userId") long userId) {
        //获取我的权益列表
        QueryWrapper<OrderGoods> orderGoodsQueryWrapper = new QueryWrapper<>();
        orderGoodsQueryWrapper.eq("user_id",userId);
        orderGoodsQueryWrapper.gt("remain_write_off_times",0);
        List<OrderGoods> orderGoodsList = orderGoodsService.list(orderGoodsQueryWrapper);
        return ResultBodyUtils.ok(orderGoodsList);
    }

    /**
     * 根据订单id获取订单商品列表
     * @param orderId
     * @return
     */
    @PostMapping("listOrderGoods")
    @Override
    public ResultBody<List<OrderGoods>> listOrderGoods(@RequestParam("orderId") long orderId) {
        QueryWrapper<OrderGoods> orderGoodsQueryWrapper = new QueryWrapper<>();
        orderGoodsQueryWrapper.eq("order_id",orderId);
        List<OrderGoods> orderGoodsList = orderGoodsService.list(orderGoodsQueryWrapper);
        return ResultBodyUtils.ok(orderGoodsList);
    }
}
